#leetcode题目88：合并两个有序数组
#难度：简单

from typing import List

class Solution:
    def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
        """
        Do not return anything, modify nums1 in-place instead.
        """
        sorted = []
        p1, p2 = 0, 0
        while p1 < m or p2 < n:
            if p1 == m:
                sorted.append(nums2[p2])
                p2 += 1
            elif p2 == n:
                sorted.append(nums1[p1])
                p1 += 1
            elif nums1[p1] < nums2[p2]:
                sorted.append(nums1[p1])
                p1 += 1
            else:
                sorted.append(nums2[p2])
                p2 += 1
        nums1[:] = sorted


#测试数据
nums1 = [1,2,3,0,0,0]
m = 3
nums2 = [2,5,6]
n = 3
#预期输出：[1,2,2,3,5,6]
solution = Solution()
solution.merge(nums1, m, nums2, n)
print(nums1)

nums1 = [1]
m = 1
nums2 = []
n = 0
#预期输出：[1]
solution = Solution()
solution.merge(nums1, m, nums2, n)
print(nums1)